angular.module('eYe')
	.controller('ThemesController', function($scope,$routeParams, $location, DataBase, safeApply, Connexion){
	
		var idTheme = (typeof $routeParams.themeId !== 'undefined')? $routeParams.themeId : 0;			
		
		$.when(
			getValueThemesAndQcm(DataBase.BD_Themes_Qcms,'id',idTheme),
			DataBase.getValueTable(DataBase.BD_Themes_Qcms,DataBase.BD_Themes_Qcms.Themes,'theme_parent',idTheme)
		).then(function(themeActuel,sous_themes){	

			themeActuel = themeActuel[0];								
			$scope.nomTheme = themeActuel.titre;							
			$scope.qcm = themeActuel.qcms;	
			
			var listeThemes = [];
			sous_themes.forEach(function(theme){
				listeThemes.push(theme);
			});
			$scope.themes = listeThemes;						
			safeApply($scope);
			
			Connexion.cacherCacheConnexion();
		});		

		$scope.afficherQcm = function(id) {
			$location.path('/qcm/'+id);
		}
	});